package com.cola.LambdaDemo11;

import org.w3c.dom.html.HTMLAppletElement;

import javax.sound.midi.Soundbank;
import java.util.Arrays;
import java.util.Comparator;

/**
 * @Grup:com.cola.LambdaDemo11
 * @Auther:cola
 * @Data:2021/3/19-2021-03-17:34
 * @version:1.0
 */
public class LambdaDemo {
    public static void main(String[] args) {
    //IEat iEat=new IEatImpl();
    /*iEat.eat();
    IEat iEat1=new IEat(){
        @Override
        public void eat() {
            System.out.println("eat bnana");
        }
    };*/
    //iEat1.eat();
    //lambda表达式
    /*//好处1.让代码更加的简洁2.不会单独生成class文件
    IEat iEat2=()->{
        System.out.println("eat apple bnana");
    };*/
    /*//没有参数时使用
    IEat iEat3=()-> System.out.println("eat apple or bnana");*/
        //iEat2.eat();
        //iEat3.eat();
    /*//带参数时使用,参数的类型可以省略
        IEat iEat4=(thing)-> System.out.println("eat..."+thing);
        iEat4.eat("apple");*/
       /* //带参数时使用,参数的类型可以省略,多行代码块
        IEat iEat5=(thing,name)->{
            System.out.println("thing--"+thing);
            System.out.println("name--"+name);
        };
        iEat5.eat("apple","colo");*/
        //带返回值的方法
        /*IEat iEat6=(thing,name)->{
            System.out.println(name+","+thing);
            return 10;
        };*/

        //带返回值的方法中只有一句实现代码
       /* IEat iEat7=(thing, name)->10;
        IEat iEat8=(thing, name)->thing==null?1:0;
        IEat iEat9=(final String thing,final String name)->thing==null?1:0;*/
    Student[] students={
            new Student("cola",15),
            new Student("super",56),
            new Student("国旗",18)
    };
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge()-o2.getAge();
            }
        });
        //Comparator<Student> c=(o1, o2) ->o1.getAge()-o2.getAge();
        Arrays.sort(students,(o1, o2) ->o1.getAge()-o2.getAge());
        System.out.println(Arrays.toString(students));
        IEat.method();
    }
}
//只有一个抽象方法的接口,可以添加默认方法和静态方法不影响
interface IEat{
    public int eat(String thing,String name);
    public default void print(){
        System.out.println("print test");
    }
    public static void method(){
        System.out.println("static method..");
    }
}

/*
class IEatImpl implements IEat{


    @Override
    public void eat(String thing,String name) {
        System.out.println("eat--"+thing);
        System.out.println("name--"+name);
    }
}*/
